<!DOCTYPE html>
<html lang="en">
<head>
    <style>
        .divcss5{ border:1px solid #F00; width:200px; height:100px}
    </style>
    <link rel="stylesheet" href="css/foot.css"/>
    <link rel="stylesheet" href="css/head.css"/>
	<link href="css/cart/common.css" rel="stylesheet" type="text/css">
    <link href="css/cart/main.css" rel="stylesheet" type="text/css">
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="js/base-v1.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery-1.2.6.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/cookie.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/common.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery.cookie.js" charset="utf-8"></script>
    <script type="text/javascript" src="s/base-2011.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery.min.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/jquery-extend.js"></script>
    <script type="text/javascript" src="js/lib-v1.js" charset="utf-8"></script>
    <link href="css/prodList.css" rel="stylesheet" type="text/css">
    <link href="css/prodInfo.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/logout.js"></script>
    <script type="text/javascript" src="js/productinfo.js"></script>
    <meta charset="UTF-8">
    <title>商品分页</title>
    <script type="text/javascript">
        var userId="";
        var productId="";
        window.onload=function(){
            var localUrl=decodeURI(window.location.href);
            //alert(localUrl);
            productId=localUrl.split("?")[1].split("=")[1];
            $.ajax({
                url:"http://www.easyhouse.com/products/item/"+productId,
                dataType:"json",
                type:"POST",
                success:function(data){
                    //图片
                    var imgUrl=data.imgUrl;
                    var productPrice = data.productPrice;
                    var houseArea = data.houseArea;
                    var unitPrice = data.productPrice/data.houseArea;
                    unitPrice = unitPrice.toFixed(2);
                    localStorage.setItem( "houseId", data.houseId );

                    document.getElementById("prod_img").src=data.imgUrl;
                    document.getElementById("prod_area").innerText=data.houseArea;
                    //document.getElementById("prod_Id").innerText=data.houseId;
                    document.getElementById("prod_unitprice").innerText=unitPrice;
                    document.getElementById("prod_name").innerText=data.houseName;
                    document.getElementById("prod_desc").innerText=data.houseDescription;
                    document.getElementById("prod_pric").innerText=data.productPrice;
                    document.getElementById("prod_addr").innerText=data.houseAddr;
                    document.getElementById("prod_province").innerText=data.addrProvince;
                    document.getElementById("prod_district").innerText=data.addrDistrict;
                }
            });
            var houseId = localStorage.getItem("houseId");
            
            $.ajax({
                url:"http://www.easyhouse.com/message/selectContent?houseId="+houseId,
                dataType:"json",
                type:"GET",
                success:function(data){
                    $("#prod_content").append();
                    if(data.rows.length>0){

                        $.each(data.rows,function(index, message){
                            $("#prod_content").append("<table width='50%' style=margin:auto; border='1' bordercolor='#3399CC' cellspacing='1'>"+
                                "<tr align='center'>"+
                                "<td width='10%'>发送人</td>"+
                                "<td width='10'>发送时间</td>"+
                                "<td width='100'>评论内容</td>"+
                                //"<td width='65'>&nbsp;</td>"+
                                "</tr>"+
                                "<tr>"+
                                "<td align='center'>"+message.userName+"</td>"+
                                "<td align='center'>"+message.messageDate+"</td>"+
                                "<td >"+message.messageContent+"</td>"+
                                "</tr>"+
                                "</table>");
                        })
                    }
                },
            });
            

            var _ticket = $.cookie("EM_TICKET");
            
            if(!_ticket){
                return ;
            }

                //当dataType类型为jsonp时，jQuery就会自动在请求链接上增加一个callback的参数
                $.ajax({
                    url : "http://www.easyhouse.com/user/query/" + _ticket,
                    dataType : "json",
                    type : "GET",
                    success : function(data){
	                    localStorage.setItem( "houseName", data.houseName );
                        //alert("好啊2");
                        if(data.status == 200){
                            var _data = JSON.parse(data.data);//jackson
                            var html =_data.userName+"，欢迎来到好房！<a href=\"javascript:void(0)\" class=\"link-logout\" onclick='logout()'>[退出]</a>  \|<a href=\"http://www.easyhouse.com/manage.html\" class=\"link-logout\">[后台]</a>";
                            userId=_data.userId;
                            $("#loginbar").html(html);
                        }

                    },
                    error : function(){
                        alert('index error.');
                    }
                });

            }

        function addCart(){
            if(userId==""){
                window.location.href="login.html";
                return;
            }
            $.ajax({
                url:"http://www.easyhouse.com/cart/save?userId="+userId+"&productId="+productId,
                dataType:"json",
                type:"GET",
                success:function (data){

                    if(data.status==200){
                        window.location.href="http://www.easyhouse.com/mycart.html?userId="+userId;
                    }else{
                        alert("新购物车失败");
                    }
                },
                error:function () {
                    alert("算了吧");
                }
            });
        }
        function search(a){
            var query=document.getElementById(a).value;
            //alert(query);
            window.location.href="./search.html?query="+query;

        }
        //添加留言	
        function message(a){
	        var _ticket = $.cookie("EM_TICKET");
	        
            if(!_ticket){
	            alert("请先登录")
                return ;
            }
	        var key=document.getElementById(a).value;
	        if(!key){
		        alert("留言不能为空!")
		        return;
	        }
	        var houseId = localStorage.getItem("houseId");
	        
	        
	        alert(key); 
            $.ajax({
	            url:"http://www.easyhouse.com/message/publish?messageContent="+key+"&houseId="+houseId+"&userName="+_ticket,
	            dataType:"json",
	            type:"GET"
            });
            
            
           	
        }
        function queryMessage() {
	        alert("queryMessage");
        	$.ajax({
                url:"http://www.easyhouse.com/message/selectContent?houseId="+houseId,
                dataType:"json",
                type:"GET",
                success:function(data){
                
                    if(data.rows.length>0){
		
                        $.each(data.rows,function(index, message){
                            $("#prod_content").append("<table width='50%' style=margin:auto; border='1' bordercolor='#3399CC' cellspacing='1'>"+
                            							"<tr align='center'>"+
                            								"<td width='10'>发送人</td>"+
                            								"<td width='10'>发送时间</td>"+
                            								"<td width='100'>评论内容</td>"+
                            								//"<td width='65'>&nbsp;</td>"+
                            							"</tr>"+
                            								"<tr>"+
                            								"<td align='center'>"+message.userName+"</td>"+
                            								"<td align='center'>"+message.messageDate+"</td>"+
                            								"<td >"+message.messageContent+"</td>"+
                            							"</tr>"+
                            						"</table>");
                        })                       
                    }
                },
            });
            alert("stop");
        }
    </script>
</head>
<body>
<div id="common_head">
	<div id="line2">
        <img id="logo" src="img/head/logo.jpg"/>
        <input type="text" value="" accesskey="s" id="key" autocomplete="off" onkeydown="javascript:if(event.keyCode==13) search('key');"/>
        <input type="button" value="搜 索" onclick="search('key')"/>
        <span id="goto">
			<a id="goto_cart" href="./mycart.html">我的房源</a>
			<a id="goto_cart" href="./talk.html">发起聊天</a>
		</span>
        <img id="erwm" src="img/head/qr.jpg"/>
    </div>
	<header class="lianjia-header"><div class="nav-wrap"><div class="wrapper"><div class="fl"><a href="https://www.lianjia.com/" class="logo"></a></div><div class="fr nav"><div class="fl"><ul>
	                              <li>
	                <a class="" href="./product-list.html?page=1&rows=5">全部房源</a>
	            </li>
	                                              <li>
	                <a class="" href="/web/sekill/list">新房</a>
	            </li>
	                                              <li>
	                <a class="" href="https://cq.lianjia.com/zufang/">租房</a>
	   
	                                  <li class="hover">
	              <a class="" href="https://cq.lianjia.com/wenda/">
	              指南
	              </a>
	              <div class="nav-list">
	                  <dd>
	                      <i></i>
	                                                                                  <dl>
	                                    <a href="https://cq.lianjia.com/wenda/">问答</a>
	                                </dl>
	                                                                                                                <dl>
	                                    <a href="https://news.lianjia.com/cq/baike/">百科</a>
	                                </dl>
																			</dd>
	              </div>
	          </li>
	                                    <li>
	                <a class="" href="https://cq.lianjia.com/tool.html" target="_blank">工具</a>
	            </li>
	                                              <li>
	                <a class="" href="https://cq.lianjia.com/yezhu/" target="_blank">发布房源</a>
	            </li>
				<li class="fore1" id="loginbar" clstag="homepage|keycount|home2013|01b">
				    <span id="head_span"\\\x><a href="login.html">登录</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="regist.html">注册</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="manage.html">后台</a></span>
				
				</li>
	                  </ul></div><div class="fr login"><div class="login-panel typeUserInfo"></div></div></div></div></header>
</div>
<div id="warp">
    <div id="left">
        <div id="left_top">
            <img src="" id="prod_img">
        </div>
        <div id="left_bottom">

        </div>
    </div>
    <div id="right">
        <div id="right_top">
            <span id="prod_name"><br/></span>
            <br>
            <span id="prod_desc"><br/></span>
        </div>
        <div id="right_middle">
				<span id="right_middle_span">
                    所在区域&nbsp;:&nbsp;<span id="prod_province"></span>&nbsp;&nbsp;<span id="prod_district"></span><br/>
                    详细区域&nbsp;:&nbsp;<span id="prod_addr"></span><br/>
                    面积&nbsp;:&nbsp;<span id="prod_area"></span>平米<br/>
                    总价&nbsp;:&nbsp;<span class="price_red" id="prod_pric"></span>元<br/>
                    单价&nbsp;:&nbsp;<span id="prod_unitprice"></span>/平米<br/>
					
                </span>
        </div>
        <div id="right_bottom">
            <input class="add_cart_but" type="button" onclick="addCart()"/>
        </div>
    </div>
</div>
    <div id="left_bottom1">
        <table width="500" border="0" align="center">
       					
                        <tr id="content" width="100%">
    						<div id="prod_content">
    						</div>
						</tr>
                        
                        
        </table>
    </div>
    <div id="xixi">
	    <table width="331" border="0" align="center">
  <tr>
    <td height="32" valign="bottom"><font size="4"><b>评论发送:</b></font></td>
  </tr>
  <tr>
    <td>
      <table width="308" border="1" bordercolor="#3399cc" cellspacing="1">
        <tr valign="top"> 
          <td width="86" align="right">评论内容:</td>
          <td width="209"> 
           	<input type="text" value="" accesskey="s" id="key2" autocomplete="off" onkeydown="javascript:if(event.keyCode==13) message('key2');"/>
        	<input type="button" value="发 送" onclick="message('key2')"/>
          </td>
        </tr>
        
      </table>
    </td>
  </tr>

  <tr>
    <td>&nbsp; </td>
  </tr>
</table>
    </div>
</div>

</body>
</html>